home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / ACROYNMity / support.c < prev    next >
Encoding:
Text File  |  2000-06-23  |  5.5 KB  |  243 lines

  1. // Acronymity
  2. // © 2000 by Karl Kornel (kornel.1@osu.edu)
  3. // Made during MacHack 2000
  4. // Changes & Redistribution allowed is credit given
  5.  
  6. /* Our includes */
  7. #include <iostream.h> // The streams
  8.  
  9. /* Our special include */
  10. #include "settings.h" // The user-definable settings
  11.  
  12. /* The prototypes for the support functions */
  13. bool confirmQuit(const char *);
  14. bool confirmAdd(const char *);
  15. void printHelp(void);
  16. void clearChar(char *,const int);
  17. void cleanAcronym(char *);
  18. bool isLetter(const char);
  19. char makeItLower(const char);
  20. int getLetterCode(const char);
  21.  
  22.  
  23. /* Our functions */
  24. bool confirmQuit(const char *acronym) {
  25.     if ( (acronym[0] == 'q') && (acronym[1] == 'u') && (acronym[2] == 'i') && (acronym[3] == 't')
  26.     && (acronym[4] == '\0') )
  27.         return true;
  28.     else
  29.         return false;
  30. }
  31.  
  32. bool confirmAdd(const char *acronym) {
  33.     if ( (acronym[0] == 'a') && (acronym[1] == 'd') && (acronym[2] == 'd') && (acronym[3] == '\0') )
  34.         return true;
  35.     else
  36.         return false;
  37. }
  38.  
  39. void printHelp(void) {
  40.     for (int temp=1;temp < 30;temp++)
  41.         cout << "\n";
  42.     cout << endl;
  43.     
  44.     cout << "Words can be up to " << wordLength << " characters long.\n"
  45.         << "To add a word, open the appropriate text file.\n"
  46.         << "The first letter of the word you want to add\n"
  47.         << " determines the text file that will hold the new word.\n"
  48.         << "For example, you would place the word\"Apple\" in the file\n"
  49.         << " named \"a.txt\", keeping each word on its own line\n" << endl
  50.         << "After adding the word, update the \"index.dat\" file\n"
  51.         << "Each line in the file has a letter, a comma, and a number.\n"
  52.         << "The letter is the name of the text file without the extension.\n"
  53.         << "The number is the number of words in each text file.\n"
  54.         << "Good luck!  This program will now quit.\n" << endl;
  55. }
  56.  
  57. void clearChar(char *theString, const int length) {
  58.     for (int temp=0;temp <= length-1;temp++)
  59.         theString[temp] = '\0';
  60.     theString[length] = '\0';
  61. }
  62.  
  63. void cleanAcronym(char *theAcronym) {
  64.     char newAcronym[acronymLength]; // Make space for the clean version
  65.     clearChar(newAcronym,acronymLength); // Initialize it
  66.     
  67.     int newAcronymLoc = 0; // Current "cursor" position
  68.     
  69.     for (int charNum=0;charNum <= acronymLength - 1;charNum++) { // Do this for each character
  70.         if (isLetter(theAcronym[charNum])) { // If it's actually a letter
  71.             newAcronym[newAcronymLoc] = makeItLower(theAcronym[charNum]); // Copy in the lowercase char.
  72.             newAcronymLoc++; // Advance the cursor by one
  73.         }
  74.     }
  75.     
  76.     for (int charNum=0;charNum <= acronymLength - 1;charNum++) // Do this for each character
  77.         theAcronym[charNum] = newAcronym[charNum]; // Transfer the character
  78.         
  79. }
  80.  
  81. bool isLetter(const char theChar) {
  82.     bool reallyLetter = false; // Are we really a letter?
  83.     char lowerLetters[27] = "abcdefghijklmnopqrstuvwxyz"; // The lower-case letters
  84.     char upperLetters[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // The upper-case letters
  85.     
  86.     for (int letter=0;letter <= 25;letter++)
  87.         if (lowerLetters[letter] == theChar)
  88.             reallyLetter = true;
  89.         else if (upperLetters[letter] == theChar)
  90.             reallyLetter = true;
  91.     
  92.     return reallyLetter;
  93. }
  94.  
  95. char makeItLower(const char theChar) {
  96.     char retValue; // The value to return
  97.     
  98.     if (theChar == 'A')
  99.         retValue = 'a';
  100.     else if (theChar == 'B')
  101.         retValue = 'b';
  102.     else if (theChar == 'C')
  103.         retValue = 'c';
  104.     else if (theChar == 'D')
  105.         retValue = 'd';
  106.     else if (theChar == 'E')
  107.         retValue = 'e';
  108.     else if (theChar == 'F')
  109.         retValue = 'f';
  110.     else if (theChar == 'G')
  111.         retValue = 'g';
  112.     else if (theChar == 'H')
  113.         retValue = 'h';
  114.     else if (theChar == 'I')
  115.         retValue = 'i';
  116.     else if (theChar == 'J')
  117.         retValue = 'j';
  118.     else if (theChar == 'K')
  119.         retValue = 'k';
  120.     else if (theChar == 'L')
  121.         retValue = 'l';
  122.     else if (theChar == 'M')
  123.         retValue = 'm';
  124.     else if (theChar == 'N')
  125.         retValue = 'n';
  126.     else if (theChar == 'O')
  127.         retValue = 'o';
  128.     else if (theChar == 'P')
  129.         retValue = 'p';
  130.     else if (theChar == 'Q')
  131.         retValue = 'q';
  132.     else if (theChar == 'R')
  133.         retValue = 'r';
  134.     else if (theChar == 'S')
  135.         retValue = 's';
  136.     else if (theChar == 'T')
  137.         retValue = 't';
  138.     else if (theChar == 'U')
  139.         retValue = 'u';
  140.     else if (theChar == 'V')
  141.         retValue = 'v';
  142.     else if (theChar == 'W')
  143.         retValue = 'w';
  144.     else if (theChar == 'X')
  145.         retValue = 'x';
  146.     else if (theChar == 'Y')
  147.         retValue = 'y';
  148.     else if (theChar == 'Z')
  149.         retValue = 'z';
  150.     else
  151.         retValue = theChar;
  152.     
  153.     return retValue;
  154. }
  155.  
  156. int getLetterCode(const char theLetter) {
  157.     int theNumber; // The number corresponding to the letter
  158.     
  159.     switch (theLetter) {
  160.     case 'a':
  161.         theNumber = 1;
  162.         break;
  163.     case 'b':
  164.         theNumber = 2;
  165.         break;
  166.     case 'c':
  167.         theNumber = 3;
  168.         break;
  169.     case 'd':
  170.         theNumber = 4;
  171.         break;
  172.     case 'e':
  173.         theNumber = 5;
  174.         break;
  175.     case 'f':
  176.         theNumber = 6;
  177.         break;
  178.     case 'g':
  179.         theNumber = 7;
  180.         break;
  181.     case 'h':
  182.         theNumber = 8;
  183.         break;
  184.     case 'i':
  185.         theNumber = 9;
  186.         break;
  187.     case 'j':
  188.         theNumber = 10;
  189.         break;
  190.     case 'k':
  191.         theNumber = 11;
  192.         break;
  193.     case 'l':
  194.         theNumber = 12;
  195.         break;
  196.     case 'm':
  197.         theNumber = 13;
  198.         break;
  199.     case 'n':
  200.         theNumber = 14;
  201.         break;
  202.     case 'o':
  203.         theNumber = 15;
  204.         break;
  205.     case 'p':
  206.         theNumber = 16;
  207.         break;
  208.     case 'q':
  209.         theNumber = 17;
  210.         break;
  211.     case 'r':
  212.         theNumber = 18;
  213.         break;
  214.     case 's':
  215.         theNumber = 19;
  216.         break;
  217.     case 't':
  218.         theNumber = 20;
  219.         break;
  220.     case 'u':
  221.         theNumber = 21;
  222.         break;
  223.     case 'v':
  224.         theNumber = 22;
  225.         break;
  226.     case 'w':
  227.         theNumber = 23;
  228.         break;
  229.     case 'x':
  230.         theNumber = 24;
  231.         break;
  232.     case 'y':
  233.         theNumber = 25;
  234.         break;
  235.     case 'z':
  236.         theNumber = 26;
  237.         break;
  238.     default: // If no letter exits (shouldn't happen)
  239.         theNumber = 1+ (rand() % 26); // Return a random number to 26
  240.     }
  241.     
  242.     return theNumber - 1; // Return the number, correcting for an array number
  243. }